home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Screensavers 98
/
Screensavers 98.iso
/
scr
/
pyro
/
fclasses.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-03-28
|
23KB
|
706 lines
#include "fclasses.h"
#include "fix.h"
int PixelSize = 1;
// ############################################################################
// Constructors
Flare::Flare (void)
{
xPos = yPos = xPlot = yPlot = ground = gravty = thrust = 0;
gndTerminated = alive = FALSE;
gravConst = (1 * Fixed) >> (random (3)+1);// gravity constant... this case it's random.
// trailer buffer settings.
overBuf = FALSE;
bufPnt = -1;
trailLen = 0;
trailer = NULL;
colour = RGB(255,255,255);
}
Flare::Flare (int x, int y,
int thr, int grav,
int cyc, int gnd,
int trailLength, COLORREF col)
{
init (x, y, thr, grav, cyc, gnd, trailLength, col);
}
void Flare::init (int x, int y,
int thr, int grav,
int cyc, int gnd,
int trailLength, COLORREF col)
{
xPos = x;
yPos = y;
thrust = thr;
ground = gnd;
cycles = cyc;
colour = col;
gravty = grav;
// init internals ***** Change XPos, yPos and assign to xPlot, yPlot *****
xPlot = yPlot = 0;
gndTerminated = FALSE; // flare hasn't hit the ground!
alive = TRUE;
//**** Allocate trailer memory ****
// If memory is already allocated, but trail length has changed. Then
// delete/free memory.
if ((trailer != NULL) && (trailLen != trailLength))
{
delete trailer;
trailer = NULL;
}
// Allocate memory
if (trailer == NULL)
trailer = new SaveXY[trailLength];
// buffer variables for trailer
trailLen = trailLength;
overBuf = FALSE;
bufPnt = -1;
}
void Flare::removePoint (HDC hdc, int x, int y)
{
if (y > ground)
y = ground;
switch (PixelSize)
{
case 1:
SetPixel(hdc, x, y, 0);
break;
case 2:
SetPixel (hdc, x, y, 0);
SetPixel (hdc, x, y+1, 0);
break;
case 3:
SetPixel (hdc, x+1, y-1, 0);
SetPixel (hdc, x, y, 0);
SetPixel (hdc, x+1, y, 0);
break;
case 4:
SetPixel(hdc, x, y, 0);
SetPixel(hdc, x-1, y, 0);
SetPixel(hdc, x, y-1, 0);
SetPixel(hdc, x-1, y-1, 0);
}
}
void Flare::showPoint (HDC hdc, int x, int y)
{
if (y > ground)
y = ground;
switch (PixelSize)
{
case 1:
SetPixel(hdc, x, y, colour);
break;
case 2:
SetPixel (hdc, x, y, colour);
SetPixel (hdc, x, y+1, colour);
break;
case 3:
SetPixel (hdc, x+1, y-1, colour);
SetPixel (hdc, x, y, colour);
SetPixel (hdc, x+1, y, colour);
break;
case 4:
SetPixel(hdc, x, y, colour);
SetPixel(hdc, x-1, y, colour);
SetPixel(hdc, x, y-1, colour);
SetPixel(hdc, x-1, y-1, colour);
}
}
BOOL Flare::move (HDC hdc)
{
if (alive)// && (trailer != NULL))
{
// update flare
if (trailLen > 0)
{
// decrement cycles of life for firework
cycles--;
yPlot = yPlot + gravty; // decrease virtical lift
xPlot = xPlot + thrust; // decrease horizontal thrust
gravty = gravty - gravConst; // update gravity pull
// **** Trailer maintenace ****
// load buffer from start
if (overBuf == FALSE)
{
// If item exceeds buffer, rollover to start of buffer (queue system)
if (bufPnt >= trailLen - 1)
{
bufPnt = -1;
overBuf = TRUE;
removePoint (hdc, trailer [bufPnt+1].x, trailer [bufPnt+1].y);
}
bufPnt++;
trailer[bufPnt].x = xPos + (xPlot / Fixed);
trailer[bufPnt].y = yPos - (yPlot / Fixed);
}
else // cycle thru queue buffer.
{
if (cycles <= trailLen)
{
removePoint (hdc, trailer [trailLen-1].x, trailer [trailLen-1].y);
trailLen--;
}
if (bufPnt >= trailLen - 1)
bufPnt = -1;
bufPnt++;
removePoint (hdc, trailer [bufPnt].x, trailer [bufPnt].y);
trailer [bufPnt].x = xPos + (xPlot / Fixed);
trailer [bufPnt].y = yPos - (yPlot / Fixed);
}
showPoint (hdc, trailer [bufPnt].x, trailer [bufPnt].y);
}
else
{
removePoint (hdc, trailer [0].x, trailer [0].y);
alive = FALSE;
}
}
return alive;
}
// ############################################################################
// Destructor
Flare::~Flare(void)
{
delete trailer;
}
// ############################################################################
// ############################################################################
// ############################################################################
void SkyRocket::init (int starBNum,
int x, int y,
int thr, int grav,
int cyc, int gnd,
int trailLength, COLORREF col)
{
//**** Allocate explode memory ****
// If memory is already allocated, but explode number has changed. Then
// delete/free memory.
if ((pStarBurst != NULL) && (starBurstNum != starBNum))
{
delete pStarBurst;
pStarBurst = NULL;
}
if (pStarBurst == NULL)
pStarBurst = new Flare[starBNum];
// Initialise main rocket ....
mainRocket.init (x, y, thr, grav, cyc, gnd, trailLength, col);
// Initialise explode variables.
explode = FALSE;
starBurstNum = starBNum;
colour = col;
trailLen = trailLength;
// Select colour item to change (i.e. increment!)
// test for single primary colours
const int incRocAmount = 3;
int testRGB = GetRValue(colour);
testRGB += GetGValue(colour);
testRGB += GetBValue(colour);
if (testRGB <= 256) // Only one colour is active
{
// Pick an primary item that isn't set!
int pick = 0;
while (pick == 0)
{
colItemChange = random (3);
switch (colItemChange)
{
case 0:
if (GetRValue(colour) < 127)
pick = -1;
break;
case 1:
if (GetGValue(colour) < 127)
pick = -1;
break;
case 2:
if (GetBValue(colour) < 127)
pick = -1;
}
}
}
else
colItemChange = random(3);
// Select the increment style according to current colour value.
switch (colItemChange)
{
// red
case 0:
if (GetRValue(colour) < 127)
colChangeAmnt = incRocAmount;
else
colChangeAmnt = -incRocAmount;
break;
// green
case 1:
if (GetGValue(colour) < 127)
colChangeAmnt = incRocAmount;
else
colChangeAmnt = -incRocAmount;
break;
// blue
case 2:
if (GetBValue(colour) < 127)